import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter01/pages/read/card_special.dart';

import 'card_free.dart';
import 'card_recommend.dart';
import 'card_share.dart';
import 'custom_appbar.dart';

class ContentPage extends StatefulWidget {
  final PageController pageController = PageController(
    initialPage: 0,
    /* 视窗比例 */
    viewportFraction: 0.8,
  );
  final void Function(int)? onPageChanged;

  ContentPage({Key? key, this.onPageChanged}) : super(key: key);

  @override
  _ContentPageState createState() => _ContentPageState();
}

class _ContentPageState extends State<ContentPage> {
  // static List<Color> _colors = [
  //   Colors.blue,
  //   Colors.red,
  //   Colors.deepOrange,
  //   Colors.teal,
  // ];

  @override
  initState() {
    _statusBar();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Colors.white10),
      child: Column(children: [
        CustomAppBar(),
        Expanded(
          child: PageView(
              controller: widget.pageController,
              onPageChanged: (index) {
                print('onPageChanged-$index');
                if (widget.onPageChanged != null) {
                  widget.onPageChanged!(index);
                }
              },
              children: [
                _wrapItem(CardRecommend()),
                _wrapItem(CardShare()),
                _wrapItem(CardFree()),
                _wrapItem(CardSpecial()),
              ]),
        ),
      ]),
    );
  }

  Widget _wrapItem(Widget widget) {
    return Padding(
        padding: EdgeInsets.all(10),
        child: widget
    );
  }

  _statusBar() {
    SystemUiOverlayStyle uiOverlayStyle = SystemUiOverlayStyle(
      systemNavigationBarColor: Color(0xFF000000),
      systemNavigationBarDividerColor: null,
      statusBarColor: Colors.transparent,
      systemNavigationBarIconBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.dark,
      statusBarBrightness: Brightness.light,
    );
    SystemChrome.setSystemUIOverlayStyle(uiOverlayStyle);
  }
}
